import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

/**
 * Created by JiaJia on 2019/4/17 0017.
 */
public class Fruit {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String[] m = sc.nextLine().split(",");
            String[] n = sc.nextLine().split(",");
            int k = sc.nextInt();
            System.out.println(maxProfit(m, n, k));
        }
        sc.close();
    }

    private static int maxProfit(String[] m, String[] n, int k) {/*
        int len = m.length;
        int[][] dp = new int[len + 1][k + 1];
        for (int i = 0; i <= len; i++)
            dp[i][0] = 0;
        for (int j = 0; j <= k; j++)
            dp[0][j] = 0;
        for (int i = 1; i <= len; i++) {
            int cost = Integer.parseInt(m[i - 1]);
            int price = Integer.parseInt(n[i - 1]);
            for (int j = 1; j <= k; j++) {
                if (j >= cost) {
                    dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - cost] + price);
                } else {
                    dp[i][j] = dp[i - 1][j];
                }
            }
        }
        return dp[len][k];*/

        int[] array=new int[m.length];
        //HashMap<Integer,Integer> map=new HashMap<>();
        int[][] temp=new int[2][m.length];
        for (int i = 0; i <m.length; i++) {
            int a = Integer.parseInt(m[i - 1]);
            int b = Integer.parseInt(n[i - 1]);
            array[i] = b - a;
            //map.put(array[i],a);
            temp[0][i]=array[i];
            temp[1][i]=a;
        }
        Arrays.sort(array);
        for (int i = array.length-1; i >=0 ; i--) {
            while (k>=0){
                //k=k-map.get(array[i])+array[i];
            }
        }
        return k;
        /*int len=m.length;
        int dp[][] = new int[len + 1][k+ 1];
        for (int i = 0; i <=len; i++)
            dp[i][0] = 0;
        for (int j = 0; j <=k; j++)
            dp[0][j] = 0;

        for (int i = 1; i <=len; i++) {
            int cost =Integer.parseInt(m[i-1]);
            int price =Integer.parseInt(n[i-1]);
            for (int j = 1; j <=k; j++) {
                if (cost <= j) {
                    if (dp[i - 1][j] < (dp[i - 1][j - cost] +price))
                        dp[i][j] = dp[i - 1][j - cost] + price;
                    else
                        dp[i][j] = dp[i - 1][j];
                } else
                    dp[i][j] = dp[i - 1][j];
            }
        }
        return dp[len][k];*/
        /*int len=m.length;
        int[] dp = new int[k+ 1];
        for (int i = 1; i <=len; i++) {
            int cost =Integer.parseInt(m[i-1]);
            int price =Integer.parseInt(n[i-1]);
            for (int j =k; j >= 1; j--) {
                if (j >=cost) {
                    dp[j] = Math.max(dp[j], dp[j-cost] + price);
                }
            }
        }
        return dp[k];
    }
*/

    }
}